package nodes.command;

import java.util.List;
import parser.ParserException;
import model.Model;
import model.Turtle;
import nodes.AbstractNode;
import nodes.ConstantNode;


/**
 * Turns the turtle left
 */
public class LeftC extends AbstractCommand
{
    public AbstractNode evaluate (List<AbstractNode> myArguments, Model model)
    {
        if (myArguments.size() != Integer.parseInt(resources.getString("left")))
        {
            throw ParserException.BAD_ARGUMENTS;
        }

        int numOfDegreesTurned = 0;
        for(Turtle currentTurtle : model.getActiveTurtles())
        {
            numOfDegreesTurned += currentTurtle.turn(myArguments.get(0).evaluate().getValue());
        }

        return new ConstantNode(numOfDegreesTurned);
    }
}
